package demo3;

public class Person implements Cloneable{
    public String name;
    public int age;
    public double score;
    public Money money=new Money();

    public Person(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {//第一步：重写clone方法
        //return super.clone();//这可以达成浅拷贝
        Person tmp=(Person) super.clone();
        tmp.money= (Money) this.money.clone();
        return tmp;//这样写会达成深拷贝
    }

}
